package com.scvtc.config.security.filter;

import com.scvtc.domain.ResResult;
import com.scvtc.utils.WebUtil;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

import static com.scvtc.domain.enums.AppHttpCodeEnum.INSUFFICIENT_PERMISSIONS;

/**
 * @Description: 授权失败处理器
 * @Author: yiFei
 * @date: 2022/2/15 22:49
 */
@Configuration
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {

    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
            accessDeniedException.printStackTrace();
            // 响应 权限不足
            WebUtil.resultJson(response, ResResult.customize(INSUFFICIENT_PERMISSIONS));
    }
}
